package adv328;

import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class ListDemo {
    public static void main(String[] args) {
        List li=new ArrayList();//内部是数组
        li.add("tiger");
        li.add("dog");
        li.add("penguiun");
        li.add("dolphin");
        li.add(Math.E);
        li.add(Math.PI);
        li.add(22);
        li.add(2>1);
        li.set(3,"小牛");//替换
        li.add(1,"pig");//指定位置上加入值
        Object d = li.remove(3);
        System.out.println(d+"被删除了");
        System.out.println(li.size());
        System.out.println(li);

        System.out.println("包含猪？"+li.contains("pig"));
        System.out.println("猪的位置："+li.indexOf("pig"));
        System.out.println("获得第四个位置："+li.get(4));
        System.out.println(">>>>>>>迭代1:for>>>>>>>>>>>>>>>>");
        for (int i = 0; i < li.size(); i++) {
            System.out.print(li.get(i)+" ");
        }
        System.out.println();
        System.out.println(">>>>>>>迭代2:增强for>>>>>>>>>>>>>>>>");
        for (Object o:li) {
            System.out.print(o+" ");
        }
        System.out.println();
        System.out.println(">>>>>>>迭代3:转换成数组>>>>>>>>>>>>>>>>");
        Object[] objects = li.toArray();
        //....
        System.out.println();

        //li.stream().
    }
}
